Skip to content

cli: Improve error message when pack lacks .nomad.tpl parent templates#831

Open
TIMMAREDDYDEEKSHITHA-ship-it wants to merge 12 commits intomainfrom
fix/issue-510-improve-error-message
Open

cli: Improve error message when pack lacks .nomad.tpl parent templates#831
TIMMAREDDYDEEKSHITHA-ship-it wants to merge 12 commits intomainfrom
fix/issue-510-improve-error-message

Conversation

@TIMMAREDDYDEEKSHITHA-ship-it
Copy link
Copy Markdown
Collaborator

@TIMMAREDDYDEEKSHITHA-ship-it TIMMAREDDYDEEKSHITHA-ship-it commented Mar 12, 2026

Description
Fixes #510

Problem

Users were confused by the unclear error "no templates were rendered by the renderer process run" when their pack lacked .nomad.tpl files. This led to hours of debugging, as reported in the issue.

Solution

Enhanced the error message to:

  • Clearly explain that .nomad.tpl files are required for parent templates
  • Show the complete template naming convention with examples
  • List the actual template files found in the pack's templates directory
  • Provide actionable guidance on how to fix the issue

Changes

  • Added ErrNoParentTemplates error constant in internal/pkg/errors/ui_context.go
  • Updated error handling in plan command (internal/cli/plan.go)
  • Updated error handling in run command (internal/cli/run.go)
  • Both commands now read the filesystem to show users which files exist

pack renders successfully with .nomad.tpl file

image

Reproducing the error ->
File structure after renaming (missing .nomad.tpl)

image

After: Improved Error Message ->
Running nomad-pack plan now shows clear, actionable error

image

Refactored UIErrorContext version of the error:

image

Reminders

  • Add CHANGELOG.md entry
  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

Copy link
Copy Markdown
Member

@hashi-divyansh hashi-divyansh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TIMMAREDDYDEEKSHITHA-ship-it Added my comment.
Missing implementation for render cmd.

@TIMMAREDDYDEEKSHITHA-ship-it
Copy link
Copy Markdown
Collaborator Author

@TIMMAREDDYDEEKSHITHA-ship-it Added my comment. Missing implementation for render cmd.

here 'render' command has different behaviour - it succeeds if it renders either parent templates or dependent pack templates. Since it has different validation logic, I kept existing generic error message for it.

The improved error message specifically addresses issue in #510 which affects 'plan' and 'run' commands where parent templates are strictly required

- Add nomadVariable() function to retrieve specific variable
- Add nomadVariables() function to list all variables
- Add comprehensive unit tests with mocked API
- Verify integration with live Nomad cluster
- Update documentation with usage examples

Closes #409
- Added ErrNoParentTemplates error constant
- Enhanced error message to explain .nomad.tpl naming requirement
- Shows template naming convention rules with examples
- Lists actual template files found in templates/ directory
- Provides specific guidance on how to fix the issue
- Applied to both plan and run commands for consistency

The new error message clearly shows users:
1. What went wrong (no .nomad.tpl files)
2. The naming convention rules
3. Which files exist that need renaming
4. How to fix the issue

This replaces the previous unclear 'no templates were rendered' error
that left users confused for hours.

Fixes #510
@TIMMAREDDYDEEKSHITHA-ship-it TIMMAREDDYDEEKSHITHA-ship-it force-pushed the fix/issue-510-improve-error-message branch from f3b90f3 to 5a56c0b Compare March 16, 2026 17:46
@TIMMAREDDYDEEKSHITHA-ship-it TIMMAREDDYDEEKSHITHA-ship-it marked this pull request as ready for review March 17, 2026 05:09
Copy link
Copy Markdown
Member

@hashi-divyansh hashi-divyansh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the PR title, it should be a bit more elaborative.

@TIMMAREDDYDEEKSHITHA-ship-it
Copy link
Copy Markdown
Collaborator Author

Please update the PR title, it should be a bit more elaborative.

Sure

@TIMMAREDDYDEEKSHITHA-ship-it TIMMAREDDYDEEKSHITHA-ship-it changed the title Fix/issue 510 improve error message cli: Improve error message when pack lacks .nomad.tpl parent templates Mar 20, 2026
hashi-divyansh
hashi-divyansh previously approved these changes Mar 20, 2026
hashi-divyansh
hashi-divyansh previously approved these changes Mar 24, 2026
Copy link
Copy Markdown
Member

@jrasell jrasell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good thanks for the recent changes. A final thought seeing that the code is duplicated in plan and run, do we want to have a helper function that can be used to generate the context in these cases? We could also then test this helper, meaning we have assertions of what is included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nomad-pack throws obtuse error when pack does not contain a parent template

3 participants